package com.soufang.soufangdemo.controller;

import com.soufang.soufangdemo.base.ApiResponse;
import com.soufang.soufangdemo.base.Status;
import com.soufang.soufangdemo.service.SearchService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/houses")
public class HouseController {
    private final SearchService searchService;

    public HouseController(SearchService searchService) {
        this.searchService = searchService;
    }

    @GetMapping("/suggestions")
    public ApiResponse<List<String>> autocomplete(String prefix) {
        if (prefix == null) {
            return ApiResponse.error(Status.BAD_REQUEST);
        }
        return ApiResponse.success(searchService.suggest(prefix));
    }
}
